Now we have very rudimentary tiff support.
authorMark Crichton <crichton@src.gnome.org>
Thu, 1 Jul 1999 06:59:07 +0000 (06:59 +0000)
committerMark Crichton <crichton@src.gnome.org>
Thu, 1 Jul 1999 06:59:07 +0000 (06:59 +0000)
Now we have very rudimentary tiff support.

I should use the loading logic in the GIMP plugin...

gdk-pixbuf/Makefile.am
gdk-pixbuf/io-tiff.c [new file with mode: 0644]

index 7c058f546d77254cf524dd28d4d12f595b5202b0..a1ff62566adeddfab60b5c7cd9ab0b5b091cba9c 100644 (file)
@@ -4,7 +4,8 @@ lib_LTLIBRARIES =               \
        libpixbuf-png.la        \
        libpixbuf-jpeg.la       \
        libpixbuf-gif.la        \
-       libpixbuf-xpm.la
+       libpixbuf-xpm.la        \
+       libpixbuf-tiff.la
 
 #
 # The GdkPixBuf library
@@ -42,3 +43,8 @@ libpixbuf_xpm_la_SOURCES =    \
 libpixbuf_gif_la_SOURCES =     \
        io-gif.c
 
+#
+# The TIFF loader
+#
+libpixbuf_gif_la_SOURCES=      \
+       io-tiff.c
diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c
new file mode 100644 (file)
index 0000000..771a052
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * io-tiff.c: GdkPixBuf I/O for TIFF files.
+ * Copyright (C) 1999 Mark Crichton
+ * Author: Mark Crichton <crichton@gimp.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* Following code (almost) blatantly ripped from Imlib */
+
+#include <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <tiffio.h>
+
+#include "gdk-pixbuf.h"
+/*#include "gdk-pixbuf-io.h" */
+
+GdkPixBuf *image_load(FILE * f)
+{
+    GdkPixBuf *pixbuf;
+    TIFF *tiff;
+    art_u8 *pixels, *tmppix;
+    gint w, h, x, y, num_pixs, fd;
+    uint32 *rast, *tmp_rast;
+
+    g_return_val_if_fail(f != NULL, NULL);
+
+    fd = fileno(f);
+    tiff = TIFFFdOpen(fd, "libpixbuf-tiff", "r");
+
+    if (!tiff)
+       return NULL;
+
+    TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
+    TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
+    num_pixs = w * h;
+
+    /* Yes, it needs to be _TIFFMalloc... */
+    rast = (uint32 *) _TIFFmalloc(num_pixs * sizeof(uint32));
+
+    if (!rast) {
+       TIFFClose(tiff);
+       return NULL;
+    }
+
+    if (TIFFReadRGBAImage(tiff, w, h, rast, 0)) {
+       pixels = art_alloc(num_pixs * 4);
+       if (!pixels) {
+           _TIFFfree(rast);
+           TIFFClose(tiff);
+           return NULL;
+       }
+       tmppix = pixels;
+
+       for (y = 0; y < h; y++) {
+           /* Unexplainable...are tiffs backwards? */
+           /* Also looking at the GIMP plugin, this
+            * whole reading thing can be a bit more
+            * robust.
+            */
+           tmp_rast = rast + ((h - y - 1) * w);
+           for (x = 0; x < w; x++) {
+               tmppix[0] = TIFFGetR(*tmp_rast);
+               tmppix[1] = TIFFGetG(*tmp_rast);
+               tmppix[2] = TIFFGetB(*tmp_rast);
+               tmppix[3] = TIFFGetA(*tmp_rast);
+               tmp_rast++;
+               tmppix += 4;
+           }
+       }
+    }
+    _TIFFfree(rast);
+    TIFFClose(tiff);
+
+    /* Return the GdkPixBuf */
+    pixbuf = g_new(GdkPixBuf, 1);
+    pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+
+    /* Ok, I'm anal...shoot me */
+    if (!(pixbuf->art_pixbuf))
+       return NULL;
+    pixbuf->ref_count = 0;
+    pixbuf->unref_func = NULL;
+
+    return pixbuf;
+}